package org.mx.test.graphql;

import graphql.schema.DataFetchingEnvironment;
import org.mx.service.rest.graphql.GraphQLAnnotationExecution;
import org.mx.service.rest.graphql.GraphQLFieldAnnotation;
import org.mx.test.service.RbacService;
import org.mx.test.service.UserBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@SuppressWarnings("javadoc")
@Service("rbacQueryExecution")
public class RbacQueryExecution implements GraphQLAnnotationExecution {
    private RbacService rbacService;

    @Autowired
    public RbacQueryExecution(RbacService rbacService) {
        super();
        this.rbacService = rbacService;
    }

    @GraphQLFieldAnnotation("getUserRbacInfo")
    public UserBean getUserRbacInfo(DataFetchingEnvironment env) {
        String userCode = env.getArgument("userCode");
        return rbacService.getUserRbacInfo(userCode);
    }

    @GraphQLFieldAnnotation("getUserRbacInfoByCache")
    public UserBean getUserRbacInfoByCache(DataFetchingEnvironment env) {
        String userCode = env.getArgument("userCode");
        return rbacService.getUserRbacInfoByCache(userCode);
    }

    @Override
    public String getTypeName() {
        return "Query";
    }
}
